package main

import (
	"fmt"
	"math"
)

func smallestRangeI(nums []int, k int) int {
	min, max := getMinMax(nums)
	res := max - min - 2*k
	if res < 0 {
		return 0
	}
	return res
}

func getMinMax(nums []int) (min, max int) {
	min = math.MaxInt32
	max = math.MinInt32
	for _, num := range nums {
		if num > max {
			max = num
		}
		if num < min {
			min = num
		}
	}
	return
}

func main() {
	nums := []int{0, 10}
	res := smallestRangeI(nums, 2)
	fmt.Println(res)
}
